"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _jsxRuntime = require("react/jsx-runtime");

var _antdV = require("antd-v4");

var _react = _interopRequireDefault(require("react"));

/**
 * 评分组件
 *
 * @param
 */
var FieldRate = function FieldRate(_ref, ref) {
  var text = _ref.text,
      mode = _ref.mode,
      render = _ref.render,
      renderFormItem = _ref.renderFormItem,
      fieldProps = _ref.fieldProps;

  if (mode === 'read') {
    var dom = (0, _jsxRuntime.jsx)(_antdV.Rate, (0, _objectSpread2.default)((0, _objectSpread2.default)({
      allowHalf: true,
      disabled: true,
      ref: ref
    }, fieldProps), {}, {
      value: text
    }));

    if (render) {
      return render(text, (0, _objectSpread2.default)({
        mode: mode
      }, fieldProps), (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
        children: dom
      }));
    }

    return dom;
  }

  if (mode === 'edit' || mode === 'update') {
    var _dom = (0, _jsxRuntime.jsx)(_antdV.Rate, (0, _objectSpread2.default)({
      allowHalf: true,
      ref: ref
    }, fieldProps));

    if (renderFormItem) {
      return renderFormItem(text, (0, _objectSpread2.default)({
        mode: mode
      }, fieldProps), _dom);
    }

    return _dom;
  }

  return null;
};

var _default = /*#__PURE__*/_react.default.forwardRef(FieldRate);

exports.default = _default;